package test;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.swing.JButton;

import javax.swing.WindowConstants;
import javax.swing.JFrame;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AdminPanel extends javax.swing.JPanel {
	private JButton jButton1;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new AdminPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public AdminPanel() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setPreferredSize(new Dimension(400, 300));
			this.setLayout(null);
			this.setOpaque(false);
			{
				jButton1 = new JButton();
				this.add(jButton1);
				jButton1.setText("Testdaten erzeugen");
				jButton1.setBounds(109, 89, 183, 50);
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jButton1ActionPerformed(evt);
					}
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void jButton1ActionPerformed(ActionEvent evt) {
		  Connection connection = null;   
	        ResultSet resultSet = null;   
	        PreparedStatement statement = null;   
	  
	        try {   
	            Class.forName("org.sqlite.JDBC");   
	            connection = DriverManager   
	                    .getConnection("jdbc:sqlite:db.db3");   
	            
	            for (int i=0;i<72;i++)
	            {

	            	String sql="insert into schueler VALUES(?,?,?,?)";
	            	statement = connection.prepareStatement(sql);   
	            	statement.setInt(1, i);
	            	statement.setString(2, "Meier" + i);
	            	statement.setString(3, "Max"+ i);
	            	int klasse=0;
	            	if (i%3==0)
	            		klasse=1;
	            	else if(i%3==1)
	            		klasse=2;
	            	else if (klasse%3==2)
	            		klasse=3;
	            	statement.setInt(4, klasse);
	            		statement   
	                    .executeUpdate();   
	            }
	        } catch (Exception e) {   
	            e.printStackTrace();   
	        } finally {   
	            try {   
	                statement.close();   
	                connection.close();   
	            } catch (Exception e) {   
	                e.printStackTrace();   
	            }   
	        }   
	}

}
